<?php

class stabilityTestController extends controllerBase {
	protected $mode = AETHER_WEB;
	protected $view = true;
	protected $helpers = array();
	protected $models = array('stabilityTest');
	protected $beforeFilters = array();
	protected $beforeAfter = array();
	
	function index() {
		$this->setVar('title', 'Stability Test');
		$this->setVar('results',
			$this->m->stabilityTest->get('all', array('columns' => array('id', 'name'), 'resultsType' => 'array'))
		);
	}

	function view() {
		$result = $this->m->stabilityTest->get($this->getParam('id'), array('results' => 'single', 'resultsType' => 'array'));
		$this->setVar('title', $result['name'] . ' | Stability Test');
		$this->setVar('results', $result);
	}
	
	function edit() {
		if($this->getParam('id')=='new') {
			$new = true;
			$this->setVar('title', 'Add | Stability Test');
		} else {
			$new = false;
			$this->setVar('title', 'Edit | Stability Test');
		}
		
		if(isset($_POST['stabilityTest'])) {
			$data = new data($_POST['stabilityTest']);

			if($this->m->stabilityTest->validate($data)) {
				$this->m->stabilityLayer->startRevision();
				$this->m->setStabilityHandler($this->m->stabilityLayer);

				if($new) {
					if($this->m->stabilityTest->insert($data)) {
						$this->h->message->add('Person added. '.$this->m->stabilityLayer->undoLink());
						$this->h->core->redirect('stabilityTest/');
					}
				} else {
					if($this->m->stabilityTest->update($this->getParam('id'), $data)) {
						$this->h->message->add('Person updated. '.$this->m->stabilityLayer->undoLink());
						$this->h->core->redirect('stabilityTest/view/'.$this->getParam('id').'/');
					}
				}
			}
		} else {
			if($new) {
				$data = new data();
			} else {
				$data = $this->m->stabilityTest->get($this->getParam('id'), array('results' => 'single'));
			}
		}
		$this->setVar('data', $data);
	}

	function delete() {
		$this->m->stabilityLayer->startRevision();
		$this->m->setStabilityHandler($this->m->stabilityLayer);
		$this->m->stabilityTest->delete($this->getParam('id'));
		$this->h->message->add('Person deleted. '.$this->m->stabilityLayer->undoLink());
		$this->h->core->redirect('stabilityTest/');
	}
}

